<template>
  <el-col class="com_class">
    <el-col class="title">充值优惠</el-col>
    <el-col style="padding-top: 24px">&nbsp;</el-col>
    <el-form
      :model="form"
      ref="form"
      size="small"
      :inline="false"
      label-width="112px"
    >
      <el-col :span="6">
        <el-form-item label="起始金额：">
          <el-input v-model="form.money" placeholder="起始金额"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="优惠比例：">
          <el-input v-model="form.proportion" placeholder="优惠比例"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="4">
        <el-form-item label="优惠状态：" prop="type">
          <el-radio v-model="form.type" :label="1">启用</el-radio>
          <el-radio v-model="form.type" :label="0">禁用</el-radio>
        </el-form-item>
      </el-col>
      <el-col :span="2">
        <el-form-item>
          <el-button type="primary" @click="save_recharge_discount"
            >确认保存</el-button
          >
        </el-form-item>
      </el-col>
    </el-form>
  </el-col>
</template>
<script>
export default {
  data() {
    return {
      form: {
        money: "",
        proportion: "",
        type:''
      },
    };
  },
  mounted() {
    this.get_recharge_discount();
  },
  methods: {
    async get_recharge_discount() {
      let res = await this.$store.dispatch("get_recharge_discount", {});
      if (!res.code) {
        this.form = {
          money: res.data.start_money,
          proportion: res.data.proportion,
          type:res.data.status
        };
      }
    },
    async save_recharge_discount() {
      let data = {
        money: Number(this.form.money),
        proportion: Number(this.form.proportion),
        status: Number(this.form.type),
      };
      if (this.form.money && this.form.proportion) {
        let res = await this.$store.dispatch("save_recharge_discount", data);
        if (!res.code) {
          this.$message({
            type: "success",
            message: "设置成功",
          });
        }
      } else {
        this.$message.error("请完整填写参数");
      }
    },
  },
};
</script>
<style lang="scss">
.class_bottom {
  background-color: #ffffff;
  padding-top: 40px;
}
</style>